﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.IMage;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.IMage
{
    public class AddImageCommandHandler : IRequestHandler<AddImageCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<ImageModel> _image;
        private readonly IMapper mapper;

        public AddImageCommandHandler(IBaseRepository<ImageModel> image, IMapper mapper)
        {
            _image = image;
            this.mapper = mapper;
        }

        
        public Task<ApiResult<int>> Handle(AddImageCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<int>();
            var image = mapper.Map<ImageModel>(request);
            _image.Add(image);
            result.Message = "图片添加成功";
            return Task.FromResult(result);

        }
    }
}
